package cn.flkj.evidence.util;

import cn.flkj.evidence.exception.UserException;


/**
 * @author 州长在手 2020/9/2 下午14:50
 */
public class ResultUtil<T> {
    public Result<T> success;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> error(String code, String msg) {
        return new Result<>(code,msg);
    }
    public static <T> Result<T> error(ResultEnum resultEnum) {
        return error(resultEnum.getCode(),resultEnum.getMsg());
    }
    public static <T> Result<T> error(UserException userException) {
        return error(userException.getCode(),userException.getMessage());
    }
}
